﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:NJL_REG_COMPANY_APPLY
	/// </summary>
	public partial class NJL_REG_COMPANY_APPLY:INJL_REG_COMPANY_APPLY
	{
		public NJL_REG_COMPANY_APPLY()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NJL_REG_COMPANY_APPLY");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_REG_COMPANY_APPLY model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NJL_REG_COMPANY_APPLY(");
			strSql.Append("ID,APPLY_TYPE,APPLY_COMPANY_ID,APPLY_COMPANY_NAME,APPLY_CONTACT_NAME,MOBILE,TEL,EMAIL,MSN,QQ,APPLY_FILE_CODE_01,APPLY_FILE_CODE_02,APPLY_FILE_CODE_03,APPLY_FILE_CODE_04,APPLY_FILE_CODE_05,APPLY_CONSULT_COUNT,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME)");
			strSql.Append(" values (");
			strSql.Append("@ID,@APPLY_TYPE,@APPLY_COMPANY_ID,@APPLY_COMPANY_NAME,@APPLY_CONTACT_NAME,@MOBILE,@TEL,@EMAIL,@MSN,@QQ,@APPLY_FILE_CODE_01,@APPLY_FILE_CODE_02,@APPLY_FILE_CODE_03,@APPLY_FILE_CODE_04,@APPLY_FILE_CODE_05,@APPLY_CONSULT_COUNT,@UPDATE_USER_NAME,@UPDATE_USER_ID,@UPDATE_DATE_TIME,@CREATE_USER_NAME,@CREATE_USER_ID,@CREATE_DATE_TIME)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_TYPE", SqlDbType.Int,4),
					new SqlParameter("@APPLY_COMPANY_ID", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_COMPANY_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@APPLY_CONTACT_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@MOBILE", SqlDbType.VarChar,50),
					new SqlParameter("@TEL", SqlDbType.VarChar,50),
					new SqlParameter("@EMAIL", SqlDbType.VarChar,200),
					new SqlParameter("@MSN", SqlDbType.VarChar,200),
					new SqlParameter("@QQ", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_01", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_02", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_03", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_04", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_05", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_CONSULT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.APPLY_TYPE;
			parameters[2].Value = model.APPLY_COMPANY_ID;
			parameters[3].Value = model.APPLY_COMPANY_NAME;
			parameters[4].Value = model.APPLY_CONTACT_NAME;
			parameters[5].Value = model.MOBILE;
			parameters[6].Value = model.TEL;
			parameters[7].Value = model.EMAIL;
			parameters[8].Value = model.MSN;
			parameters[9].Value = model.QQ;
			parameters[10].Value = model.APPLY_FILE_CODE_01;
			parameters[11].Value = model.APPLY_FILE_CODE_02;
			parameters[12].Value = model.APPLY_FILE_CODE_03;
			parameters[13].Value = model.APPLY_FILE_CODE_04;
			parameters[14].Value = model.APPLY_FILE_CODE_05;
			parameters[15].Value = model.APPLY_CONSULT_COUNT;
			parameters[16].Value = model.UPDATE_USER_NAME;
			parameters[17].Value = model.UPDATE_USER_ID;
			parameters[18].Value = model.UPDATE_DATE_TIME;
			parameters[19].Value = model.CREATE_USER_NAME;
			parameters[20].Value = model.CREATE_USER_ID;
			parameters[21].Value = model.CREATE_DATE_TIME;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_REG_COMPANY_APPLY model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NJL_REG_COMPANY_APPLY set ");
			strSql.Append("APPLY_TYPE=@APPLY_TYPE,");
			strSql.Append("APPLY_COMPANY_ID=@APPLY_COMPANY_ID,");
			strSql.Append("APPLY_COMPANY_NAME=@APPLY_COMPANY_NAME,");
			strSql.Append("APPLY_CONTACT_NAME=@APPLY_CONTACT_NAME,");
			strSql.Append("MOBILE=@MOBILE,");
			strSql.Append("TEL=@TEL,");
			strSql.Append("EMAIL=@EMAIL,");
			strSql.Append("MSN=@MSN,");
			strSql.Append("QQ=@QQ,");
			strSql.Append("APPLY_FILE_CODE_01=@APPLY_FILE_CODE_01,");
			strSql.Append("APPLY_FILE_CODE_02=@APPLY_FILE_CODE_02,");
			strSql.Append("APPLY_FILE_CODE_03=@APPLY_FILE_CODE_03,");
			strSql.Append("APPLY_FILE_CODE_04=@APPLY_FILE_CODE_04,");
			strSql.Append("APPLY_FILE_CODE_05=@APPLY_FILE_CODE_05,");
			strSql.Append("APPLY_CONSULT_COUNT=@APPLY_CONSULT_COUNT,");
			strSql.Append("UPDATE_USER_NAME=@UPDATE_USER_NAME,");
			strSql.Append("UPDATE_USER_ID=@UPDATE_USER_ID,");
			strSql.Append("UPDATE_DATE_TIME=@UPDATE_DATE_TIME,");
			strSql.Append("CREATE_USER_NAME=@CREATE_USER_NAME,");
			strSql.Append("CREATE_USER_ID=@CREATE_USER_ID,");
			strSql.Append("CREATE_DATE_TIME=@CREATE_DATE_TIME");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@APPLY_TYPE", SqlDbType.Int,4),
					new SqlParameter("@APPLY_COMPANY_ID", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_COMPANY_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@APPLY_CONTACT_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@MOBILE", SqlDbType.VarChar,50),
					new SqlParameter("@TEL", SqlDbType.VarChar,50),
					new SqlParameter("@EMAIL", SqlDbType.VarChar,200),
					new SqlParameter("@MSN", SqlDbType.VarChar,200),
					new SqlParameter("@QQ", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_01", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_02", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_03", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_04", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_FILE_CODE_05", SqlDbType.VarChar,20),
					new SqlParameter("@APPLY_CONSULT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = model.APPLY_TYPE;
			parameters[1].Value = model.APPLY_COMPANY_ID;
			parameters[2].Value = model.APPLY_COMPANY_NAME;
			parameters[3].Value = model.APPLY_CONTACT_NAME;
			parameters[4].Value = model.MOBILE;
			parameters[5].Value = model.TEL;
			parameters[6].Value = model.EMAIL;
			parameters[7].Value = model.MSN;
			parameters[8].Value = model.QQ;
			parameters[9].Value = model.APPLY_FILE_CODE_01;
			parameters[10].Value = model.APPLY_FILE_CODE_02;
			parameters[11].Value = model.APPLY_FILE_CODE_03;
			parameters[12].Value = model.APPLY_FILE_CODE_04;
			parameters[13].Value = model.APPLY_FILE_CODE_05;
			parameters[14].Value = model.APPLY_CONSULT_COUNT;
			parameters[15].Value = model.UPDATE_USER_NAME;
			parameters[16].Value = model.UPDATE_USER_ID;
			parameters[17].Value = model.UPDATE_DATE_TIME;
			parameters[18].Value = model.CREATE_USER_NAME;
			parameters[19].Value = model.CREATE_USER_ID;
			parameters[20].Value = model.CREATE_DATE_TIME;
			parameters[21].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_REG_COMPANY_APPLY ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_REG_COMPANY_APPLY ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_REG_COMPANY_APPLY GetModel(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,APPLY_TYPE,APPLY_COMPANY_ID,APPLY_COMPANY_NAME,APPLY_CONTACT_NAME,MOBILE,TEL,EMAIL,MSN,QQ,APPLY_FILE_CODE_01,APPLY_FILE_CODE_02,APPLY_FILE_CODE_03,APPLY_FILE_CODE_04,APPLY_FILE_CODE_05,APPLY_CONSULT_COUNT,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME from NJL_REG_COMPANY_APPLY ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			NJL.Model.NJL_REG_COMPANY_APPLY model=new NJL.Model.NJL_REG_COMPANY_APPLY();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_TYPE"]!=null && ds.Tables[0].Rows[0]["APPLY_TYPE"].ToString()!="")
				{
					model.APPLY_TYPE=int.Parse(ds.Tables[0].Rows[0]["APPLY_TYPE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["APPLY_COMPANY_ID"]!=null && ds.Tables[0].Rows[0]["APPLY_COMPANY_ID"].ToString()!="")
				{
					model.APPLY_COMPANY_ID=ds.Tables[0].Rows[0]["APPLY_COMPANY_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_COMPANY_NAME"]!=null && ds.Tables[0].Rows[0]["APPLY_COMPANY_NAME"].ToString()!="")
				{
					model.APPLY_COMPANY_NAME=ds.Tables[0].Rows[0]["APPLY_COMPANY_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_CONTACT_NAME"]!=null && ds.Tables[0].Rows[0]["APPLY_CONTACT_NAME"].ToString()!="")
				{
					model.APPLY_CONTACT_NAME=ds.Tables[0].Rows[0]["APPLY_CONTACT_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MOBILE"]!=null && ds.Tables[0].Rows[0]["MOBILE"].ToString()!="")
				{
					model.MOBILE=ds.Tables[0].Rows[0]["MOBILE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TEL"]!=null && ds.Tables[0].Rows[0]["TEL"].ToString()!="")
				{
					model.TEL=ds.Tables[0].Rows[0]["TEL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["EMAIL"]!=null && ds.Tables[0].Rows[0]["EMAIL"].ToString()!="")
				{
					model.EMAIL=ds.Tables[0].Rows[0]["EMAIL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MSN"]!=null && ds.Tables[0].Rows[0]["MSN"].ToString()!="")
				{
					model.MSN=ds.Tables[0].Rows[0]["MSN"].ToString();
				}
				if(ds.Tables[0].Rows[0]["QQ"]!=null && ds.Tables[0].Rows[0]["QQ"].ToString()!="")
				{
					model.QQ=ds.Tables[0].Rows[0]["QQ"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_FILE_CODE_01"]!=null && ds.Tables[0].Rows[0]["APPLY_FILE_CODE_01"].ToString()!="")
				{
					model.APPLY_FILE_CODE_01=ds.Tables[0].Rows[0]["APPLY_FILE_CODE_01"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_FILE_CODE_02"]!=null && ds.Tables[0].Rows[0]["APPLY_FILE_CODE_02"].ToString()!="")
				{
					model.APPLY_FILE_CODE_02=ds.Tables[0].Rows[0]["APPLY_FILE_CODE_02"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_FILE_CODE_03"]!=null && ds.Tables[0].Rows[0]["APPLY_FILE_CODE_03"].ToString()!="")
				{
					model.APPLY_FILE_CODE_03=ds.Tables[0].Rows[0]["APPLY_FILE_CODE_03"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_FILE_CODE_04"]!=null && ds.Tables[0].Rows[0]["APPLY_FILE_CODE_04"].ToString()!="")
				{
					model.APPLY_FILE_CODE_04=ds.Tables[0].Rows[0]["APPLY_FILE_CODE_04"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_FILE_CODE_05"]!=null && ds.Tables[0].Rows[0]["APPLY_FILE_CODE_05"].ToString()!="")
				{
					model.APPLY_FILE_CODE_05=ds.Tables[0].Rows[0]["APPLY_FILE_CODE_05"].ToString();
				}
				if(ds.Tables[0].Rows[0]["APPLY_CONSULT_COUNT"]!=null && ds.Tables[0].Rows[0]["APPLY_CONSULT_COUNT"].ToString()!="")
				{
					model.APPLY_CONSULT_COUNT=int.Parse(ds.Tables[0].Rows[0]["APPLY_CONSULT_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString()!="")
				{
					model.UPDATE_USER_NAME=ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString()!="")
				{
					model.UPDATE_USER_ID=ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString()!="")
				{
					model.UPDATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString()!="")
				{
					model.CREATE_USER_NAME=ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString()!="")
				{
					model.CREATE_USER_ID=ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString()!="")
				{
					model.CREATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,APPLY_TYPE,APPLY_COMPANY_ID,APPLY_COMPANY_NAME,APPLY_CONTACT_NAME,MOBILE,TEL,EMAIL,MSN,QQ,APPLY_FILE_CODE_01,APPLY_FILE_CODE_02,APPLY_FILE_CODE_03,APPLY_FILE_CODE_04,APPLY_FILE_CODE_05,APPLY_CONSULT_COUNT,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
			strSql.Append(" FROM NJL_REG_COMPANY_APPLY ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,APPLY_TYPE,APPLY_COMPANY_ID,APPLY_COMPANY_NAME,APPLY_CONTACT_NAME,MOBILE,TEL,EMAIL,MSN,QQ,APPLY_FILE_CODE_01,APPLY_FILE_CODE_02,APPLY_FILE_CODE_03,APPLY_FILE_CODE_04,APPLY_FILE_CODE_05,APPLY_CONSULT_COUNT,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
			strSql.Append(" FROM NJL_REG_COMPANY_APPLY ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "NJL_REG_COMPANY_APPLY";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

